package teshop.view.catalog;

import java.io.Serializable;
import java.util.List;

import javax.annotation.PostConstruct;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import teshop.domain.Category;
import teshop.service.CatalogService;

@Component("listCategories")
@Scope("conversation.access")
public class ListCategories implements Serializable {

	private static final long serialVersionUID = -1820670725720413844L;
	
	private CatalogService catalogService;
	
	private List<Category> categories;

	/**
	 * Default empty Constructor for class: ListCategories
	 */
	public ListCategories() {	
	}
	
	@Autowired
	public ListCategories(CatalogService pCatalogService) {	
		this.catalogService = pCatalogService;
		categories = catalogService.getAllCategories();
	}
	
	@PostConstruct
	public void onLoad() {
//		String categoryId = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("categoryId");
//		if (categoryId != null && categoryId != "") {
//			this.categoryId = Long.valueOf(categoryId);
//			parent = catalogService.getCategory(this.categoryId).getParentCategory();
//			categories = catalogService.getSubCategories(this.categoryId);
//		}
	}

	public List<Category> getCategories() {
		return categories;
	}
	
}
